<template>
    <div>
        <!-- 搜索表单 -->
        <el-form :inline="true" :model="searchFrom" ref="searchFrom" class="demo-form-inline" style="text-align:center">
            <el-form-item label="用户ID" prop="memberId">
                <el-input v-model="searchFrom.memberId" placeholder="用户ID"></el-input>
            </el-form-item>
            <el-form-item label="用户名字" prop="memberName">
                <el-input v-model="searchFrom.memberName" placeholder="用户名字"></el-input>
            </el-form-item>
            <el-form-item label="类型名称" prop="carConfigName">
                <el-input v-model="searchFrom.carConfigName" placeholder="类型名称"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" @click="searchBtn()">查询</el-button>
                <el-button type="warning" icon="el-icon-refresh" @click="resetSearchForm()">重置</el-button>
            </el-form-item>
        </el-form>

        <!-- 表格 -->
        <el-table :data="tableData" stripe style="width: 100%">
            <el-table-column prop="id" label="编号"/>
            <el-table-column prop="carConfigName" label="车辆类型名称"/>
            <el-table-column prop="memberId" label="用户Id"/>
            <el-table-column prop="memberName" label="用户名字"/>
            <el-table-column prop="content" label="评价内容"/>
            <el-table-column prop="addtime" label="评价时间"/>
            <el-table-column prop="useNum" label="点赞数量"/>
<!--            <el-table-column align="right">-->
<!--                <template slot-scope="scope">-->
<!--                    <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>-->
<!--                </template>-->
<!--            </el-table-column>-->
        </el-table>

        <!-- 分页 -->
        <div class="block" style="text-align:center">
            <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="pageNum"
                    :page-sizes="[1, 2, 5, 10,20]"
                    :page-size="pageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="total">
            </el-pagination>
        </div>

    </div>
</template>

<script>
    export default {
        data: function () {
            return {
                tableData: [],
                total: 0, // 总条数
                pageNum: 1, // 当前页数
                pageSize: 5, // 每页显示几条
                searchFrom: {},
            }
        },
        methods: {
            // 重置表格
            resetSearchForm() {
                this.searchFrom = {}
                this.getAllComment();
            },
            // 查询表单提交
            searchBtn() {
                this.pageNum = 1;
                this.getAllComment();
            },
            //每页显示几条改变
            handleSizeChange(val) {
                this.pageSize = val;
                this.getAllComment();
            },
            // 当前是第几页改变
            handleCurrentChange(val) {
                this.pageNum = val;
                this.getAllComment();
            },
            // 获得表格数据
            getAllComment() {
                this.$http.post('cs/carComment/queryAll?pageSize=' + this.pageSize + '&pageNum=' + this.pageNum, this.searchFrom)
                    .then(res => {
                        this.tableData = res.data.t.list;
                        this.total = res.data.t.total
                    })
            },
            // 删除按钮
            handleDelete(row) {
                this.$confirm('此操作将永久删除该类型, 是否继续?', '提示', {
                    confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning', center: true
                }).then(() => {
                    this.$http.delete("cs/carConfig/delete/" + row.id).then(res => {
                        if (Number(res.data.resultCode) === 2000) {
                            this.$message({type: 'success', message: '删除成功!'});
                            this.getAllComment();
                        } else {
                            this.$message({type: 'error', message: '系统异常'});
                        }
                    })
                }).catch(() => {
                    this.$message({type: 'info', message: '已取消删除'});
                });
            },

            // 重置表单
            resetForm() {
                this.configFrom = {}
                this.dialogVisible = false;
            }

        },
        mounted() {
            this.getAllComment();
        }
    }
</script>

<style scoped>

</style>